import React, { Component } from 'react'
import { Query } from 'react-apollo'
import orgDashboard from 'graphql/org/dashboard.graphql'
import Loading from 'components/loading'
import Chart from './chart'

export default class Dashboard extends Component {
  componentDidMount() {
    const { setParentActiveItem } = this.props
    setParentActiveItem('dashboard')
  }

  render() {
    const { org } = this.props
    return (
      <Query query={orgDashboard} variables={{ uid: org.owner_object.id }}>
        {({ loading, error, data }) => {
          if (loading) return <Loading />
          if (error) return `Error! ${error.message}`
          return <Chart dashboard={data} />
        }}
      </Query>
    )
  }
}
